package com.gateway.service.filter.route;

import com.gateway.api.util.BeanUtil;
import com.gateway.service.annotation.GatewayFilterAttr;
import com.gateway.service.filter.GatewayFilter;
import com.gateway.service.runner.RequestContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

/**
 * @Description: 这个包做转发数据
 * @author: shaoyu1
 * @date: 2019/11/4 15:59
 */
@GatewayFilterAttr(type = "route")
@Slf4j
public class ExecuteRouteFilter extends GatewayFilter {

    @Override
    public void run() {
        log.info(this.getClass().getSimpleName()+" is running! ");
        RestTemplate restTemplate = BeanUtil.getBean(RestTemplate.class);
        RequestContext ctx = RequestContext.getCurrentContext();
        RequestEntity requestEntity = ctx.getRequestEntity();
        ResponseEntity responseEntity = restTemplate.exchange(requestEntity,byte[].class);
        ctx.setResponseEntity(responseEntity);
    }
}
